<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .dad {
      width: 200px;
      height: 200px;
      background-color: pink;
    }

    .son {
      width: 100px;
      height: 100px;
      background-color: purple;
    }
  </style>
</head>

<body>
  <div class="dad">
    <div class="son"></div>
  </div>
  <script>
    /* 鼠标经过事件：
    > mouseover和mouseout会有冒泡效果
    > mouseenter和mouseleave没有冒泡效果 (推荐)*/
    const dad = document.querySelector('.dad')
    const son = document.querySelector('.son')
    /* dad.addEventListener('mouseover', function () {
      console.log('鼠标经过')  //会有冒泡效果
    })
    dad.addEventListener('mouseout', function () {
      console.log('鼠标离开')  //会有冒泡效果
    }) */
    dad.addEventListener('mouseenter', function () {
      console.log('鼠标经过')  //不会有冒泡效果,推荐
    })
    dad.addEventListener('mouseleave', function () {
      console.log('鼠标离开')  //不会有冒泡效果,推荐
    })
  </script>
</body>

</html>